import { createApp } from "vue";
import "./style.css";
import * as icons from "@ant-design/icons-vue";
import { createFromIconfontCN } from "@ant-design/icons-vue";
import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import App from "./App.vue";
import router from "@/router/index.js";
import { useRoutesStore, useMenu } from "@/store/index";
import hasPerm from "@/directive/permission.js";

const app = createApp(App);
app.directive("hasPerm", hasPerm);

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
app.use(pinia);

const IconFont = createFromIconfontCN({
  scriptUrl: "//at.alicdn.com/t/c/font_4652764_r8wcfnct9d.js", // 在 iconfont.cn 上生成
});

// 全局注册所有图标
Object.keys(icons).forEach((key) => {
  if (key === "default") return;
  app.component(key, icons[key]);
});

// const menuStore = useMenu();
// menuStore.arrToTree();
const routesStore = useRoutesStore();
routesStore.handleRoutes();

window.$router = router;
app.use(router).component("IconFont", IconFont).mount("#app");
